import os
from dotenv import load_dotenv

# 加载环境变量（指定.env文件路径）
env_path = os.path.join(os.path.dirname(__file__), '..', '.env')
if os.path.exists(env_path):
    load_dotenv(env_path)
    print(f"Loading .env from: {env_path}")
else:
    print(f".env file not found at: {env_path}")
    # 尝试从当前目录加载
    load_dotenv()
    print("Trying to load .env from current directory")

print(f"BAIDU_APPID: {os.getenv('BAIDU_APPID', 'NOT_FOUND')}")
print(f"BAIDU_SECRET_KEY: {os.getenv('BAIDU_SECRET_KEY', 'NOT_FOUND')}")

class Settings:
    """应用配置类"""
    PROJECT_NAME: str = "三江译舟后端"
    VERSION: str = "1.0.0"
    FRAMEWORK: str = "FastAPI"

    # 数据库配置
    DB_URL: str = os.getenv("DATABASE_URL", "mysql+pymysql://root:18987244902Yy@localhost:3306/ynuEdu?charset=utf8mb4")

    # JWT配置
    JWT_SECRET: str = os.getenv("JWT_SECRET", "supersecret")
    JWT_ALGORITHM: str = os.getenv("JWT_ALGORITHM", "HS256")
    JWT_EXPIRE_MINUTES: int = int(os.getenv("JWT_EXPIRE_MINUTES", "60"))

    # 应用配置
    DEBUG: bool = os.getenv("DEBUG", "True").lower() == "true"
    HOST: str = os.getenv("HOST", "0.0.0.0")
    PORT: int = int(os.getenv("PORT", "8220"))

    # 安全配置
    PASSWORD_MIN_LENGTH: int = 6
    USERNAME_MIN_LENGTH: int = 3
    USERNAME_MAX_LENGTH: int = 50

    # API配置
    API_V1_PREFIX: str = "/api"
    DOCS_URL: str = "/docs"
    REDOC_URL: str = "/redoc"
    
    # 百度翻译API配置
    BAIDU_APPID: str = os.getenv("BAIDU_APPID", "dgGUJ6EWJM2feJujNpWPZXHT")
    BAIDU_SECRET_KEY: str = os.getenv("BAIDU_SECRET_KEY", "OrrnYUhGpX0S5DNrMSHuU3owSZrKZdUC")
    BAIDU_API_URL: str = "https://fanyi-api.baidu.com/api/trans/vip/translate"

# 创建全局配置实例
settings = Settings()


